package com.dpiinc.TechPage.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.dpiinc.TechPage.R;
import com.dpiinc.TechPage.user.setting.MyInfoActivity;

public class BottomBarActivity extends TabActivity {

    private TabHost mTabHost;
    private LayoutInflater mInflater;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottombar);

        initView();
    }

    private void initView() {

        // 实例化TabHost对象，得到TabHost
        mTabHost = getTabHost();

        // 实例化布局对象
        mInflater = LayoutInflater.from(this);


        // 为Tab按钮设置图标、文字和内容
        TabHost.TabSpec tabSpec = mTabHost.newTabSpec(getString(R.string.bottom_note))
                .setIndicator(getTabItemView(R.drawable.bottombar_note,R.string.bottom_note))
                .setContent(getTabItemIntent(NoteListActivity.class));
        // 将Tab按钮添加进Tab选项卡中
        mTabHost.addTab(tabSpec);

//        tabSpec = mTabHost.newTabSpec(getString(R.string.MyStore))
//                .setIndicator(getTabItemView(R.drawable.bottombar_store,R.string.MyStore))
//                .setContent(getTabItemIntent(StoreActivity.class));
//        // 将Tab按钮添加进Tab选项卡中
//        mTabHost.addTab(tabSpec);

        tabSpec = mTabHost.newTabSpec(getString(R.string.bottom_my))
                .setIndicator(getTabItemView(R.drawable.bottombar_myinfo,R.string.bottom_my))
                .setContent(getTabItemIntent(MyInfoActivity.class));
        // 将Tab按钮添加进Tab选项卡中
        mTabHost.addTab(tabSpec);

    }

    /**
     * 给Tab按钮设置图标和文字
     */
    private View getTabItemView(int imageId,int textId) {
        View view = mInflater.inflate(R.layout.item_bottombar_view, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.image_icon);
        if (imageView != null) {
            imageView.setImageResource(imageId);
        }
        TextView textView = (TextView) view.findViewById(R.id.text_name);
        textView.setText(textId);
        return view;
    }

    /**
     * 给Tab选项卡设置内容（每个内容是一个Activity）
     */
    private Intent getTabItemIntent(Class activity) {
        Intent intent = new Intent(this, activity);
        return intent;
    }
}
